package com.ruoyi.shopping_cart.service.impl;

import java.util.List;

import com.ruoyi.place.domain.Place;
import com.ruoyi.place.mapper.PlaceMapper;
import com.ruoyi.product.domain.Product;
import com.ruoyi.product.mapper.ProductMapper;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.shopping_cart.mapper.ShoppingCartMapper;
import com.ruoyi.shopping_cart.domain.ShoppingCart;
import com.ruoyi.shopping_cart.service.IShoppingCartService;

/**
 * 购物车Service业务层处理
 * 
 * @author 张富饶
 * @date 2025-05-20
 */
@Service
public class ShoppingCartServiceImpl implements IShoppingCartService 
{
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private PlaceMapper placeMapper;
    /**
     * 查询购物车
     * 
     * @param cartId 购物车主键
     * @return 购物车
     */
    @Override
    public ShoppingCart selectShoppingCartByCartId(Long cartId)
    {
//
        ShoppingCart shoppingCart = shoppingCartMapper.selectShoppingCartByCartId(cartId);
        System.err.println(shoppingCart);
        Long cartId1 = shoppingCart.getCartId();
        User user = userMapper.selectUserByUserId(cartId1);
        shoppingCart.setUser(user);
//        User user = userMapper.selectUserByUserId(shoppingCart.getUserId());
//        shoppingCart.setUser(user);
//        User user = shoppingCart.getUser();
//        Long userId = user.getUserId();
//        User user1 = userMapper.selectUserByUserId(userId);
//        shoppingCart.setUser(user1);
//
//        Place place = placeMapper.selectPlaceById(shoppingCart.getPlaceId());
//        System.err.println(place);
//        shoppingCart.setPlace(place);
        Place place = shoppingCart.getPlace();
        System.err.println(place);
        Long id = place.getId();
        Place place1 = placeMapper.selectPlaceById(id);
        shoppingCart.setPlace(place);

//        Product product = productMapper.selectProductById(shoppingCart.getProductId());
//        shoppingCart.setProduct(product);
//        Product product = shoppingCart.getProduct();
//        shoppingCart.setProduct(product);

//        Product product = shoppingCart.getProduct();
        Long productId = shoppingCart.getCartId();
        Product product1 = productMapper.selectProductById(productId);
        shoppingCart.setProduct(product1);
        return shoppingCart;
//        return shoppingCartMapper.selectShoppingCartByCartId(cartId);
    }

    /**
     * 查询购物车列表
     * 
     * @param shoppingCart 购物车
     * @return 购物车
     */
    @Override
    public List<ShoppingCart> selectShoppingCartList(ShoppingCart shoppingCart)
    {
        return shoppingCartMapper.selectShoppingCartList(shoppingCart);
    }

    /**
     * 新增购物车
     * 
     * @param shoppingCart 购物车
     * @return 结果
     */
    @Override
    public int insertShoppingCart(ShoppingCart shoppingCart)
    {
        return shoppingCartMapper.insertShoppingCart(shoppingCart);
    }

    /**
     * 修改购物车
     * 
     * @param shoppingCart 购物车
     * @return 结果
     */
    @Override
    public int updateShoppingCart(ShoppingCart shoppingCart)
    {
        return shoppingCartMapper.updateShoppingCart(shoppingCart);
    }

    /**
     * 批量删除购物车
     * 
     * @param cartIds 需要删除的购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingCartByCartIds(Long[] cartIds)
    {
        return shoppingCartMapper.deleteShoppingCartByCartIds(cartIds);
    }

    /**
     * 删除购物车信息
     * 
     * @param cartId 购物车主键
     * @return 结果
     */
    @Override
    public int deleteShoppingCartByCartId(Long cartId)
    {
        return shoppingCartMapper.deleteShoppingCartByCartId(cartId);
    }
}
